package com.egg.ylt.presenter.impl;

import com.egg.ylt.Utils.API;
import com.egg.ylt.Utils.Constants;
import com.egg.ylt.pojo.RelationEntity;
import com.egg.ylt.pojo.RelativeFamilyEntity;
import com.egg.ylt.presenter.IPhoneInvitePresenter;
import com.egg.ylt.view.IPhoneInviteView;
import com.yonyou.framework.library.bean.ErrorBean;
import com.yonyou.framework.library.common.CommonUtils;
import com.yonyou.framework.library.mvp.impl.BasePresenter;
import com.yonyou.framework.library.net.ReqCallBack;
import com.yonyou.framework.library.net.RequestManager;

import java.util.HashMap;

/**
 * Created by qiuzhenhuan on 2019/1/19.
 */

public class PhoneInvitePresenterImpl extends BasePresenter<IPhoneInviteView> implements IPhoneInvitePresenter {

    @Override
    public void inviteByPhone(String phone,String babyId,String relationshipId,String relationshipName) {

        HashMap<String, String> hashMap = new HashMap<>();
        hashMap.put("companyId", Constants.COMPANYID);
        hashMap.put("token", Constants.TOKEN);
        hashMap.put("phone", phone);
        hashMap.put("babyId", babyId);
        hashMap.put("relationshipId", relationshipId);
        hashMap.put("relationshipName", relationshipName);
        RequestManager.getInstance().requestPostByAsyn(API.ADD_USER_RELATIVE, hashMap, new ReqCallBack<Object>() {

            @Override
            public void onReqSuccess(Object result) {
                mView.showInviteSuccess();
            }

            @Override
            public void onFailure(String result) {
                CommonUtils.makeEventToast(mContext, result, false);
            }

            @Override
            public void onReqFailed(ErrorBean error) {
                CommonUtils.makeEventToast(mContext, error.getMsg(), false);
            }
        });
    }

    public void getRelationList() {
        mView.showDialogLoading("正在加载中...");
        HashMap<String, String> hashMap = new HashMap<>();
        hashMap.put("token", Constants.TOKEN);
        hashMap.put("companyId", Constants.COMPANYID);
        RequestManager.getInstance().requestGetByAsyn(API.GET_RELATION_LIST, hashMap, new ReqCallBack<RelationEntity>() {
            @Override
            public void onReqSuccess(RelationEntity result) {
                mView.dismissDialogLoading();
                mView.updateRelationList(result.getList());
            }

            @Override
            public void onFailure(String result) {
                mView.dismissDialogLoading();
                mView.showError(result);
            }

            @Override
            public void onReqFailed(ErrorBean error) {
                mView.dismissDialogLoading();
                mView.showError(error.getMsg());
            }
        });
    }
}
